#include "kernel/syspub.h"
#include "ctype.h"

int XipAscToHex(unsigned char dat, unsigned char *new)
{
    if ((toupper(dat) >= '0') && (toupper(dat) <= '9'))
       *new = toupper(dat) - '0';
    else if ((toupper(dat) >= 'A') && (toupper(dat) <= 'F'))
       *new = toupper(dat) - 'A' + 10;
    else if ((toupper(dat) >= 'a') && (toupper(dat) <= 'f'))
       *new = toupper(dat) - 'a' + 10;
    else
       return -1;

  return 0;

}

int XipStrToHex(unsigned char *read, unsigned char *write, int len)
{
    unsigned char dat;

    while(len--)
    {
       /*if (AscToHex(*read++, &dat))*/
       if (XipAscToHex(*read++, &dat))
          return -1;
       *write = *write << 4 | dat;
       if (!(len & 1))
       {
          ++write;
       }
    }

    return 0;

}

